package stream;

//创建Arraylist集合，添加字符串，前姓名，后年龄
//"zhangsan,23" "lisi,24"   "wangwu,23"
//保留年龄大于等于24的人，并收集到map集合中，姓名为键，年龄为值

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Test2 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"zhangsan,23","lisi,24","wangwu,25");
//        Map<String, Integer> m = list.stream()
//                .filter(s -> Integer.parseInt(s.split(",")[1]) >= 24)
////                .forEach(s -> System.out.println(s))
//                .collect(Collectors.toMap(new Function<String, String>() {
//                    @Override
//                    public String apply(String s) {
//                        return s.split(",")[0];
//                    }
//                }, new Function<String, Integer>() {
//                    @Override
//                    public Integer apply(String s) {
//                        return Integer.parseInt(s.split(",")[1]);
//                    }
//                }));
        Map<String, Integer> map = list.stream()
                .filter(s -> Integer.parseInt(s.split(",")[1]) >= 24)
//                .forEach(s -> System.out.println(s))
                .collect(Collectors.toMap( s -> s.split(",")[0],
                        s -> Integer.parseInt(s.split(",")[1])
                ));
        System.out.println(map);
        map.forEach((name, age) -> System.out.println(name + "=" + age));

    }
}
